<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>投票活动列表</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">

    <#assign currentMenu="activity"/>

    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>投票活动列表</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/xxxx/list" method="post"  style="margin-top: 20px">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive">
                    <table class="table table-hover table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>投票主题</th>
                            <th>投票类型</th>
                            <th>投票状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list pageInfo.list as a>
                            <tr>
                                <td>${a_index+1}</td>
                                <td>${a.title}</td>
                                <td>${(a.type?string('多选','单选'))!}</td>
                                <td>${(a.status?string('投票中','停止投票'))!}</td>
                                <td>
                                    <a  class="btn btn-info btn-xs btn-input"  data-id='${a.id}' data-status='0'>
                                        <span class="glyphicon glyphicon-arrow-right"></span> 投票
                                    </a>
                                </td>
                            </tr>
                        </#list>
                        </tbody>
                    </table>
                    <#include "/common/page.ftl" >
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl" >
</div>
<#--点击投票查出所有的信息，并且跳转页面-->
<script>
    $(".btn-input").click(function () {
        var id = $(this).data('id');
        var status = $(this).data('status');
        updateStatus(id,status);
        $.post('/activity/input',{id:id},function (data) {//返回的结果若为true则可以投票
            if (data.success) {
                Swal.fire({
                    /*text:'确认发布？',*/
                    icon: 'success',
                    confirmButtonColor:'#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '更新成功'
                }).then((result) => {
                    window.location.href = '/activity/item?id='+id;
                })
            } else {
                Swal.fire(
                    data.msg,
                    '',
                    'error'
                )
            }
        })
        })

    function updateStatus(id, status) {
        $.post('/activityItem/updateStatus', {id: id, status: status}, function (data) {
                /*if (data.success) {
                    Swal.fire({
                        text: '更新成功',
                        icon: 'success',
                        confirmButtonText: 'OK'
                    }).then((result) => {
                        if (result.value){
                            //window.location.reload();//刷新当前页面，带上原有参数
                        }
                    })
                } else {
                    Swal.fire(
                        data.msg,
                        '',
                        'error'
                    )
                }*/
            }
        )
    }

</script>




</body>
</html>
